import { CARTLIST, SELECTIDS, SELECTEDPROLIST, SESSIONSELECT } from './mutations-types'
import { getStore, setStore } from '@/untils/storage'
export default{
  [CARTLIST] (state, list) {
    if (list.resultCode === 2000) {
      state.cartlist = list.data
      const cartLists = list.data
      if (cartLists) {
        cartLists.map((item, index) => {
          if (index === 0) {
            state.shopCartId = item.id
            state.cartlength = item.productList.length
          }
        })
      }
    }
  },
  [SELECTIDS] (state, str) {
    setStore('selecteds', str)
    state.selectedIds = str
  },
  [SELECTEDPROLIST] (state, arr) {
    setStore('selectedProList', arr)
    state.selectedProList = arr
  },
  [SESSIONSELECT] (state) {
    const _arr = getStore('selectedProList')
    state.selectedProList = JSON.parse(_arr)  // session中对content 进行JSON.stringify
  }
}
